package com.binvshe.binvshe.app.home;

import com.binvshe.binvshe.common.http.ListDataRequestListener;
import com.binvshe.binvshe.common.http.MyHttpRequest;
import com.binvshe.binvshe.common.http.UrlCenter;
import com.binvshe.binvshe.organization.OpusAdapter;
import com.binvshe.binvshe.organization.entity.OpusListEntity;
import com.pachong.android.baseuicomponent.adapter.RecyclerViewBaseAdapter;
import com.pachong.android.baseuicomponent.fragment.SwipeListFragment;
import com.pachong.android.framework.httprequest.IHttpRequest;
import com.pachong.android.framework.httprequest.UrlParams;

/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2016/9/22
 */

public class RecommendFragemt extends SwipeListFragment {
    private int mPage = 0;


    @Override
    public void onResume() {
        super.onResume();
        onStartLoading();
    }

    @Override
    public RecyclerViewBaseAdapter createAdapter() {
        return new OpusAdapter(getActivity());
    }

    @Override
    public void onStartLoading() {
        getRecommendList();
    }

    @Override
    public void onStartRefreshing() {
        super.onStartRefreshing();
        mPage = 0;
        getData().clear();
        onStartLoading();
    }

    ListDataRequestListener<OpusListEntity> mRequestListener = new ListDataRequestListener(this, OpusListEntity.class, true);

    /**
     * 获取首页推荐列表
     */
    private void getRecommendList() {
        if (mPage == 0 || mRequestListener.getResponseDataParser().hasMore()) {
            mPage++;
            IHttpRequest request = new MyHttpRequest(getContext());
            UrlParams params = new UrlParams();
            params.put("page", mPage + "");
            request.get(UrlCenter.GET_CLUB_RECOMMEND, params, mRequestListener);
        }

    }


}
